//
// Created by 刘禹晨 on 16/7/23.
// Copyright (c) 2016 yuchenliu. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController()
{
    UIImageView *navBarHairlineImageView;
}
@end

@implementation BaseNavigationController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.barTintColor = [[UIColor new] initWithRed:255.0f/255.0f green:73.0f/255.0f blue:64.0f/255.0f alpha:1.0f];
    self.navigationBar.translucent = NO;
    self.navigationBar.tintColor = [UIColor whiteColor];
    NSMutableDictionary *barsytle = [NSMutableDictionary dictionary];
    [barsytle setObject:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1.0f] forKey:NSForegroundColorAttributeName];
    [self.navigationBar setTitleTextAttributes:barsytle];
    navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationBar];
}

- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    navBarHairlineImageView.hidden = YES;
}

//在页面消失的时候就让出现
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    navBarHairlineImageView.hidden = NO;
}

/**
 * 设置白色状态栏
 */
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
@end